import Vue from 'vue'
import App from './App.vue'
import router from './router'

//引入ElementUI
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)

//引入vue-table-with-tree-grid插件
import treeTable from 'vue-table-with-tree-grid'
Vue.component('tree-table', treeTable)

//引入Timeline时间线组件
// import Timeline from './assets/timeline/index'
// import TimelineItem from './assets/timeline-item/index'
// Vue.use(Timeline)
// Vue.use(TimelineItem)


//引入全局样式表
import './assets/css/globle.css'
//导入字体图标
import './assets/fonts/iconfont.css'

//导入富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
//导入富文本编辑器对应的样式
import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme
//将富文本编辑器注册为全局可用的组件
Vue.use(VueQuillEditor, /* { default global options } */ )

// 导入NProgress进度条
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

import axios from 'axios';
//配置请求的根路径
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/';
// axios请求拦截  在request中 展示进度条
axios.interceptors.request.use(config => {
  NProgress.start();
  // 为请求头对象，添加 Token 验证的 Authorization 字段
  config.headers.Authorization = window.sessionStorage.getItem('token')
  // 必须return
  return config
})
//在response中 隐藏进度条
axios.interceptors.response.use(config => {
  NProgress.done();
  return config
})
Vue.prototype.$axios = axios;

Vue.config.productionTip = false

//日期过滤器 
// 使用时: <template slot-scope="scope">
// {{ scope.row.*** | format('yyyy-MM-dd hh:mm:ss') }}
// </template> 即可
Vue.filter('format', function (val, date1) {
  function dateFormat(date, format) {
    if (typeof date === "string") {
      var mts = date.match(/(\/Date\((\d+)\)\/)/);
      if (mts && mts.length >= 3) {
        date = parseInt(mts[2]);
      }
    }
    date = new Date(date);
    if (!date || date.toUTCString() == "Invalid Date") {
      return "";
    }
    var map = {
      "M": date.getMonth() + 1, //月份 
      "d": date.getDate(), //日 
      "h": date.getHours(), //小时 
      "m": date.getMinutes(), //分 
      "s": date.getSeconds(), //秒 
      "q": Math.floor((date.getMonth() + 3) / 3), //季度 
      "S": date.getMilliseconds() //毫秒 
    };

    format = format.replace(/([yMdhmsqS])+/g, function (all, t) {
      var v = map[t];
      if (v !== undefined) {
        if (all.length > 1) {
          v = '0' + v;
          v = v.substr(v.length - 2);
        }
        return v;
      } else if (t === 'y') {
        return (date.getFullYear() + '').substr(4 - all.length);
      }
      return all;
    });
    return format;
  }
  return dateFormat(val, date1)
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
